<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<!-- 此页面是用来发布个人通知的，即一个人给另一个人发布消息，仅个人可见。   杨卓霖-->
<head>
    <meta charset="UTF-8">
    <title>个人通告</title>
    <!-- load css -->
    <link rel="stylesheet" type="text/css" href="myconfig/layui/css/layui.css" media="all">
    <!-- 加载js文件-->
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="myconfig/layui/layui.js"></script>
    <style>
        #demoTable{
            text-align: center;
            margin: 0 auto;
        }
        #sj{
            width: 490px;
            margin-left: 110px;
        }
        #bt{
            margin-top: 10px;
        }
    </style>
</head>
<body>

<div class="layui-form" style="width: 600px" id="demoTable"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
    <h2>发布个人通告:</h2><br>
    <div style="height: 15px">

    </div>
    <div class="layui-form-item" id="btt">
    <label class="layui-form-label">接收人:</label>
    <div class="layui-form" id="sj">
        <select name="sx_accepter_id" lay-verify="" id="accepter">
            <option value="">请选择...</option>
        </select>
    </div>
    </div>
    <div style="height: 20px">

    </div>
    <div class="layui-form-item" id="bt">
        <label class="layui-form-label">个人通告标题:</label>
        <div class="layui-input-block">
            <input type="text" name="userNtTitle"  id="noticeTitle" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div style="height: 20px">

    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">请填写通告内容:</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" name="userNtContent" id="userNtContent"></textarea>
        </div>
    </div>
    <div style="height: 20px">

    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="*" onclick="submitUserNotice()">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
</div>
<script>
    layui.use('form', function(){
        var form = layui.form;
        //各种基于事件的操作，下面会有进一步介绍
    });
    var $;
    var element;
    var form;
    layui.use(['layer','element','jquery','laydate','form'],function () {
        form =layui.form;
        layer = layui.layer;
        $ = layui.jquery;
        element = layui.element;
        laydate = layui.laydate;
        findAccepter()
    })

    function findAccepter() {
          $.ajax({
              url:"sx/findFounder",
              type:"post",
              datatype:"json",
              success:function (data) {
                 var accepter = document.getElementById("accepter");
                 for (var i = 0;i<data.length;i++){
                     var option = document.createElement("option");
                    option.setAttribute("value",data[i].userId);
                    option.innerText = data[i].userName;
                    accepter.appendChild(option);
                     layui.form.render('select');
                 }
              }

          })
    }


    function submitUserNotice() {
        $.ajax({
            url:"notice/addPersonalNotice",
            type:"post",
            datatype: "json",
            data:{
                userId:$("#accepter").val(),
                userNtContent:$("#userNtContent").val(),
                userNtTitle:$("#noticeTitle").val()
            },
            success:function (data) {
               // alert(data);
              if (data=="添加成功!"){
                  layer.msg('添加成功!', {
                      icon: 1,
                      time: 800,
                  },function () {
                      close1();
                  });
              }else {
                  layer.msg('添加失败!', {
                      icon: 0,
                      time: 800,
                  },function () {
                      close1();
                  });
              }

            }

        })
    }
 function close1() {
     window.location.reload();
 }
</script>
</body>
</html>